# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/8/6 9:18
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/rpc_dao.git
# @File    : user_service.py
# @Software: PyCharm
# @Version: 2.7.5
from db import car_profile_dao
from utils import my_decorator
from idl_output.ttypes import CarProfileDB
from py3_utils import my_thrift


@my_decorator.handle_exception()
def add_car_profile(car):
	return car_profile_dao.add_car_profile(car)


@my_decorator.handle_exception()
def get_carprofile(user_id, customer_id, license_no, vin_no, engine_no, register_date):
	orm_data = car_profile_dao.get_car_profile(user_id, customer_id, license_no, vin_no, engine_no, register_date)
	if not orm_data:
		return None

	thrift_data = CarProfileDB()
	my_thrift.obj_copy_with_same_name(orm_data, thrift_data)
	return thrift_data


@my_decorator.handle_exception()
def get_carfile_list(user_id, customer_id):
	orm_data = car_profile_dao.get_carfile_list(user_id, customer_id)
	if not orm_data:
		return None

	thrift_list = []
	for i in orm_data:
		thrift_data = CarProfileDB()
		my_thrift.obj_copy_with_same_name(i, thrift_data)
		thrift_list.append(thrift_data)
	return thrift_list


@my_decorator.handle_exception()
def get_carfile_license_no_list(user_id, customer_id, license_no):
	orm_data = car_profile_dao.get_carfile_license_no_list(user_id, customer_id, license_no)
	if not orm_data:
		return None

	thrift_list = []
	for i in orm_data:
		thrift_data = CarProfileDB()
		my_thrift.obj_copy_with_same_name(i, thrift_data)
		thrift_list.append(thrift_data)
	return thrift_list



